# -*- coding:utf-8 -*-
# __author__ : "张百科"
# Date: 2021/1/23 19:28
# File: brand.py
# IDE: PyCharm
from rest_framework import serializers
from django.contrib.auth.models import User
from django.conf import settings
from models.brand import Brand
from rest_framework.validators import UniqueValidator

class BrandSerializer(serializers.ModelSerializer):

    name=serializers.CharField(label='品牌名称', max_length=20,  help_text='品牌名称',
                                 validators=[
                                     UniqueValidator(
                                         queryset=Brand.objects.all(),
                                         message='该品牌已存在'
                                     )
                                 ],
                                 error_messages={
                                     ## 键值对，对应上面的限制条件，以及对应的提示
                                     'max_length': '最长20个字符'
                                 }
                                 )
    logo = serializers.CharField(label='logo', help_text='logo', required=False)
    remark = serializers.CharField(label='备注', max_length=500, help_text='备注', allow_blank=True,
                                   required=False,
                                   error_messages={
                                       'max_length': '最长500个字符'
                                   })
    class Meta:
        model = Brand
        exclude = ('is_delete',)
